package com.cdm.forum.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
public class Result<T> {


    @JsonInclude(JsonInclude.Include.ALWAYS) //一定参与序列化
    //状态码
    private int code;

    @JsonInclude(JsonInclude.Include.ALWAYS) //一定参与序列化
    //描述信息
    private String massage;

    @JsonInclude(JsonInclude.Include.ALWAYS) //一定参与序列化
    //数据
    private T data;

    public Result(int code, String massage) {
        this.massage = massage;
        this.code = code;
    }

    public Result(int code, String massage, T data) {
        this.code = code;
        this.massage = massage;
        this.data = data;
    }

    /**
     * 成功
     * @return
     */
    public static Result success() {
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.message);
    }

    public static Result success(String massage) {
        return new Result(ResultCode.SUCCESS.getCode(), massage);
    }

    public static <T> Result<T> success(T data) {
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.message, data);

    }

    public static <T> Result<T> success(String massage , T data) {
        return new Result(ResultCode.SUCCESS.getCode(), massage, data);

    }
    /**
     * 失败
     */

    public  static Result failed() {
        return new Result(ResultCode.FAILED.getCode(), ResultCode.FAILED.message);
    }

    public static Result failed(String massage) {
        return new Result(ResultCode.FAILED.getCode(), massage);
    }

    public static Result failed(ResultCode resultCode) {
        return new Result(resultCode.getCode(), resultCode.message);
    }
}
